import { ref } from "vue";
import { defineStore } from "pinia";
import { getActivityDetailList } from "@/api/wlxz/act_detail";

export const useActivityDetailStore = defineStore("activityDetail", () => {
    
    // 活动详情列表数组 - 存储学号、姓名、活动id、录取状态等字段的集合
    const activityDetailList = ref([]);
    
    // 查询活动详情列表方法
    const loadActivityDetailList = async (query = {}) => {
        try {
            const response = await getActivityDetailList({
                // activityId: query.activityId || 0,
                // status: query.status || '',
                ...query
            });
            if (response.code === 200) {
                // 存储返回的数组数据
                activityDetailList.value = response.rows || [];
                
                console.log("查询活动详情列表",response.rows)
                return {
                    code: 200,
                    data: response.rows || [],
                    total: response.total || 0
                };
            } else {
                activityDetailList.value = [];
                return {
                    code: response.code,
                    msg: response.msg || '获取活动详情列表失败',
                    data: [],
                    total: 0
                };
            }
        } catch (error) {
            console.error('获取活动详情列表失败:', error);
            activityDetailList.value = [];
            return {
                code: 500,
                msg: '网络错误，请稍后重试',
                data: [],
                total: 0
            };
        }
    };
    
    return {
        activityDetailList,
        loadActivityDetailList
    };
});